home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / ib.754 < prev    next >
Text File  |  1992-02-06  |  3KB  |  64 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Ohlfs;\f2\fswiss Helvetica;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 loadable palettes IB Interface Builder\
  8. \
  9. Q:  I've created a palette object with subviews.  These subviews are created within the 
  10. \b init:
  11. \b0  method for my object.  I store the 
  12. \b id's
  13. \b0  for these subviews in instance variables in the object.  When I instantiate one of these objects by dragging it from the palette, the subviews are there—they are visible—yet none of my code for resizing or accessing these subviews is working.  Why?\
  14. \
  15. Q:  When I instantiate and initialize one of my palette objects, the instance variables do not contain the values to which they were initialized.  What's going on?\
  16. \
  17. A:  If you debug the object that you have written within the context of Interface Builder (try using 
  18. \b fprintf(stderr, ...)
  19. \b0  statements, if nothing else), you will discover that all of the instance variables and outlets are nil, even though at one point all of the instance variables were initialized and the objects to which the outlets once pointed still exist.  This is because the object is being archived and unarchived.  It is your responsibility to provide the specific archiving and unarchiving code for each of your objects.  This is accomplished within the 
  20. \b read:
  21. \b0  and 
  22. \b write:
  23. \b0  methods for your object.  Within those methods, you must read and write 
  24. \i all
  25. \i0  of the instance variables for your object—even the 
  26. \b id's
  27. \b0 .  If you do not do this, then instance variables will contain bogus values, and outlets will become disconnected even though the objects themselves exist.  (View archiving automatically handles archiving and unarchiving subviews.)\
  28. \
  29. Here is a code snippet which illustrates what you must do.  The object in question contains six instance variables: 1 string, 2 booleans, and 3 id's which point to subviews of the object.\
  30.  
  31. \fc0 \
  32.  
  33. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\f1\fs22\fc0     - read:(NXTypedStream*)stream\
  34.     \{\
  35.         [super read:stream];\
  36.         NXReadTypes(stream,"cii", myTitle, &bordered, &gridEnabled);\
  37.         \
  38.     /* read in the id's for the outlets */\
  39.         myTitleField = NXReadObject(stream);\
  40.         grapherView = NXReadObject(stream);\
  41.         nameField = NXReadObject(stream);\
  42.         return self;\
  43.     \}\
  44. \
  45.     - write:(NXTypedStream*)stream\
  46.     \{\
  47.         [super write:stream];\
  48.         NXWriteTypes(stream,"cii", myTitle, &bordered, &gridEnabled);\
  49. \
  50.     /* write the id's for the outlets */\
  51.         NXWriteObjectReference(stream, myTitleField);\
  52.         NXWriteObjectReference(stream, grapherView);\
  53.         NXWriteObjectReference(stream, nameField);\
  54.         return self;\
  55.     \}\
  56.  
  57. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\fs28\fc0 \
  58. QA754\
  59. \
  60. Not valid for 1.0\
  61. Valid for 2.0\
  62. \
  63.  
  64.